/*
 * VectorUtilsTest.cpp
 *
 *  Created on: 06-12-2010
 *      Author: Przemek
 */

#include "utils/VectorUtils.hpp"

#define BOOST_TEST_MODULE VectorUtils test
#include <boost/shared_ptr.hpp>
#include <boost/test/unit_test.hpp>
using std::vector;
using boost::shared_ptr;

BOOST_AUTO_TEST_CASE( containsTest )
{
	vector<int> v;
	v.push_back(10);

	BOOST_CHECK_EQUAL(VectorUtils::contains<int>(v, 10), true);
	BOOST_CHECK_EQUAL(VectorUtils::contains<int>(v, -10), false);
}

BOOST_AUTO_TEST_CASE( findTest )
{
	vector<int> v;
	v.push_back(10);

	BOOST_CHECK_EQUAL((VectorUtils::find<int>(v, 10) != v.end()), true);
	BOOST_CHECK_EQUAL((VectorUtils::find<int>(v, -10) == v.end()), true);
}

BOOST_AUTO_TEST_CASE( findInSharedPtrVectorTest )
{
	vector<shared_ptr<int> > v;

	int* first = new int(2);
	v.push_back(shared_ptr<int>(first));
	v.push_back(shared_ptr<int>(new int(3)));

	BOOST_CHECK_EQUAL((VectorUtils::findInSharedPtrVector<int>(v, first) == v.begin()), true);
	shared_ptr<int> nonExisting = shared_ptr<int> (new int(12));
	BOOST_CHECK_EQUAL((VectorUtils::findInSharedPtrVector<int>(v, nonExisting.get()) == v.end()), true);
}

